package com.example.administrator.printoutindemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class StoreListOutStorageListAdapter extends BaseAdapter{
	private Context mContext = null;
	private LayoutInflater mInflater = null;
	private Outstorage outstorage = null;

	private List<OutStorageListMaterialInfo> li_outstorage = null;

	private class ViewHolder {
		TextView txt_title;
	}

	private ViewHolder holder = null;

	public StoreListOutStorageListAdapter(Context context) {
		// TODO Auto-generated constructor stub
		mContext = context;
	}

	public void setList(List<OutStorageListMaterialInfo> li_outstorage) {

		this.li_outstorage = li_outstorage;

		this.mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub

		int result = 0;
		if (null != li_outstorage) {
			result = li_outstorage.size();
		}
		return result;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		Object result = null;
		if (null != li_outstorage) {
			result = li_outstorage.get(position);
		}

		return result;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		int result = 0;
		if (null != li_outstorage) {
			result = li_outstorage.size();
		}
		return result;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null) {

			holder = new ViewHolder();

			convertView = mInflater.inflate(R.layout.store_adapter_listqrcode,
					null);

			holder.txt_title = (TextView) convertView
					.findViewById(R.id.txt_title);

			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		if (null != this.li_outstorage) {

			OutStorageListMaterialInfo c = li_outstorage.get(position);

			String [] suppliers = c.get_supplier().split("\\|");

			String status = suppliers[1];

			holder.txt_title.setText(""+c.get_projectname()+","
					+c.get_material()+" "+c.get_real_count()+c.get_unit() +" " +status);

		}

		return convertView;
	}
}